package com.itheima.demo08.Synchronized;

public class RunnableImpl implements Runnable {
    private static int ticket = 100;

    @Override
    public void run() {
        while (ticket>0) {
            payTicketStatic();
        }
    }
    public static synchronized void payTicketStatic() {
        if (ticket > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->正在卖第" + ticket + "张票");
            ticket--;
        }
    }

    /*public synchronized void payTicket() {
        if (ticket > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->正在卖第" + ticket + "张票");
            ticket--;
        }
    }*/
}
